var pagecount = 5;
var index = 0;
$(function () {
    getResource();
    getResourceNews();
    getResourceupload();
    getBookList();

    // 回车事件绑定
    $('#souSuo').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            self.location.href = "xq_list.html?type=souSuo&keyWord=" + $("#souSuo").val();
        }
    });
})

// 精彩一课
function getResource() {
    var data = {
        type: "WONDERFUL_LESSON",
        page: 0,
        size: 5
    };
    AjaxSubmit("GET", data, basePath + "/common/resource/searchCommonResource", getResource_fun);
}
function getResource_fun(res) {
    var videoLists = res.obj.content;
    //console.log(res);
    if (res.status == "SUCCESS") {
        $.each(videoLists, function (i, videoList) {
            if (videoList.field4 == "1") {
                $(".jcyk").find(".gonggao").find("ul").append('<a href="' + videoList.fileUrl + '"><li>' +
                    '<img src="' + basePath + videoList.pic + '" alt="" class="img-rounded pull-left">' +
                    '<img src="../img/start.png" alt="" class="startimg">' +
                    '<div class="pull-left movielist">' +
                    '<p>' + videoList.title + '</p>' +
                    '<p class="movieNum"><span class="pull-right">' + toHourMinute(videoList.videoTime) + '</span></p>' +
                    '</div>' +
                    '</li></a>');
            } else {
                $(".jcyk").find(".gonggao").find("ul").append('<a onclick=toXqVideo("' + videoList.id + '","jcyk")><li>' +
                    '<img src="' + basePath + videoList.pic + '" alt="" class="img-rounded pull-left">' +
                    '<img src="../img/start.png" alt="" class="startimg">' +
                    '<div class="pull-left movielist">' +
                    '<p>' + videoList.title + '</p>' +
                    '<p class="movieNum"><span class="pull-right">' + toHourMinute(videoList.videoTime) + '</span></p>' +
                    '</div>' +
                    '</li></a>');
            }
        })
    }
}

// 教学案例
function getResourceNews() {
    var data = {
        commonNewsTypeId: 7,
        page: index,
        size: pagecount
    };
    AjaxSubmit("GET", data, basePath + "/common/resource/getNews", getResourceNews_fun);
}
function getResourceNews_fun(res) {
    var newsResourceLists = res.obj.content;
    //console.log(res);
    if (res.status == "SUCCESS") {
        $.each(newsResourceLists, function (i, newsResourceList) {
            $(".jxal").find(".sizheng").find("ul").append('<a onclick=toXqNormal("' + newsResourceList.id + '","fourBook_jiaoXueAnLi")><li class="clearfix"> ' +
                // '<img src="' + newsResourceList.pic + '" alt="" class="img-rounded pull-left"> ' +
                '<div class="pull-left right-list"> ' +
                '<p>' + newsResourceList.title + '</p> ' +
                '<p class="small"> ' +
                '<span class="longsmall pull-left">' + newsResourceList.abstructContent + '</span> ' +
                '<span class="pull-right" style="margin-left:50px;">浏览' + newsResourceList.pageView + '次</span> ' +
                '<span class="pull-right">' + changeTime(newsResourceList.creatTime) + '</span> ' +
                '</p> ' +
                '</div> ' +
                '</li></a>')
        })
    }
}

// 最新上传资源
function getResourceupload() {
    var data = {
        page: index,
        size: pagecount
    };
    AjaxSubmit("GET", data, basePath + "/common/resource/searchCommonResource", getResourceupload_fun);
}
function getResourceupload_fun(res) {
    //console.log(res);
    var uploadResourceLists = res.obj.content;
    if (res.status == "SUCCESS") {
        $.each(uploadResourceLists, function (i, uploadResourceList) {
            if (i == uploadResourceLists.length - 1) {
                $(".zxsczy_ul").append('<a onclick=toXqNormal("' + uploadResourceList.id + '","zxsczy")><li class="clearfix last-li"> ' +
                    '<div class="pull-left News">' +
                    uploadResourceList.title +
                    '</div> ' +
                    '<div class="pull-right time">' +
                    changeTime(uploadResourceList.creatTime) +
                    '</div> ' +
                    '</li></a>')
            } else {
                $(".zxsczy_ul").append('<a onclick=toXqNormal("' + uploadResourceList.id + '","zxsczy")><li class="clearfix"> ' +
                    '<div class="pull-left News">' +
                    uploadResourceList.title +
                    '</div> ' +
                    '<div class="pull-right time">' +
                    changeTime(uploadResourceList.creatTime) +
                    '</div> ' +
                    '</li></a>')
            }
        })
    }
}

// 获取七本书
function getBookList() {
    var data = {};
    AjaxSubmit("GET", data, basePath + "/common/resource/getBookList", getBookList_fun);
}
function getBookList_fun(res) {
    console.log(res);
    var BookLists = res.obj;
    if (res.status == "SUCCESS") {
        $.each(BookLists, function (i, BookList) {
            if (BookList.useType !== "THE_USE_OF_THE_TEACHING_MATERIALS_IN_THE_ELECTIVE_COURSE_OF_IDEOLOGICAL_AND_POLITICAL_AFFAIRS") {
                if (i == 4) {
                    $(".lessonDiv").find("ul").append('<li>' +
                        '<a href="thematicClassification.html">' +
                        '<img src="' + BookList.pic + '" alt=""> ' +
                        '<p>' + BookList.bookName + '</p>' +
                        '</a>' +
                        '</li>');
                } else if (i == 5) {
                    $(".lessonDiv").find("ul").append('<li>' +
                        '<a href="jx_zjjs.html">' +
                        '<img src="' + BookList.pic + '" alt="">' +
                        '<p>' + BookList.bookName + '</p>' +
                        '</a>' +
                        '</li>');
                } else {
                    $(".lessonDiv").find("ul").append('<li>' +
                        '<a href="jx_fourBook.html?bookId=' + BookList.id + '">' +
                        '<img src="' + BookList.pic + '" alt="">' +
                        '<p>' + BookList.bookName + '</p>' +
                        '</a>' +
                        '</li>');
                }
            }
        })
    }
}

// 跳转至详情
function toXqNormal(followId, type) {
    var followId = followId;
    var theType = type;
    sessionStorage.setItem("followId", JSON.stringify(followId));
    sessionStorage.setItem("type", JSON.stringify(theType));
    self.location.href = "xq.html";
}

// 跳转至视频
function toXqVideo(followId, type) {
    var followId = followId;
    var theType = type;
    sessionStorage.setItem("followId", JSON.stringify(followId));
    sessionStorage.setItem("type", JSON.stringify(theType));
    window.open("video.html");
}